<!DOCTYPE html>
<html>
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="utf-8">
  
  <title>数据结构复习之kmp算法 | 探花需拔根</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  
    <meta name="keywords" content="Bluarry,bluarry,Blog,探花,拔根,博客,区块链,算法,acm">
  
  <meta name="description" content="考研时复习专业课时，顺带复习并记录了下来">
<meta name="keywords" content="算法,数据结构,复习">
<meta property="og:type" content="article">
<meta property="og:title" content="数据结构复习之kmp算法">
<meta property="og:url" content="/2018/11/07/2018-11-07-数据结构复习之kmp算法/index.html">
<meta property="og:site_name" content="探花需拔根">
<meta property="og:description" content="考研时复习专业课时，顺带复习并记录了下来">
<meta property="og:locale" content="zh.yml">
<meta property="og:image" content="https://cdn.bluarry.top/wp-content/uploads/2019/12/a.png">
<meta property="og:image" content="https://cdn.bluarry.top/wp-content/uploads/2019/12/b.png">
<meta property="og:image" content="https://cdn.bluarry.top/wp-content/uploads/2019/12/c.png">
<meta property="og:image" content="https://cdn.bluarry.top/wp-content/uploads/2019/12/b.png">
<meta property="og:image" content="https://cdn.bluarry.top/wp-content/uploads/2019/12/d.png">
<meta property="og:image" content="https://cdn.bluarry.top/wp-content/uploads/2019/12/2_a.png">
<meta property="og:image" content="https://cdn.bluarry.top/wp-content/uploads/2019/12/2_b.png">
<meta property="og:image" content="https://cdn.bluarry.top/wp-content/uploads/2019/12/2_c.png">
<meta property="og:image" content="https://cdn.bluarry.top/wp-content/uploads/2019/12/2_d.png">
<meta property="og:image" content="https://cdn.bluarry.top/wp-content/uploads/2019/12/3.png">
<meta property="og:image" content="https://cdn.bluarry.top/wp-content/uploads/2019/12/4_b.png">
<meta property="og:updated_time" content="2020-03-02T12:53:47.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="数据结构复习之kmp算法">
<meta name="twitter:description" content="考研时复习专业课时，顺带复习并记录了下来">
<meta name="twitter:image" content="https://cdn.bluarry.top/wp-content/uploads/2019/12/a.png">
  
  
    <link rel="icon" href="/favicon.ico">
  
  <link href="//cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">
  <link rel="stylesheet" href="/css/style.css">
  <script src="/js/pace.min.js"></script>
  

  
  

  
<!-- Matomo -->
<script type="text/javascript">
	var _paq = window._paq || [];
	/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
	_paq.push(['trackPageView']);
	_paq.push(['enableLinkTracking']);
	(function() {
	  var u="//matomo.bluarry.top/";
	  _paq.push(['setTrackerUrl', u+'matomo.php']);
	  _paq.push(['setSiteId', '3']);
	  var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
	  g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
	})();
  </script>
  <!-- End Matomo Code -->

</head>
</html>
<body>
  <div id="container">
      <header id="header">
    <div id="banner"></div>
    <div id="header-outer">
        <div id="header-menu" class="header-menu-pos animated">
            <div class="header-menu-container">
                <a href="/" class="left">
                    <span class="site-title">探花需拔根</span>
                </a>
                <nav id="header-menu-nav" class="right">
                    
                    <a  href="/">
                        <i class="fa fa-home"></i>
                        <span>主页</span>
                    </a>
                    
                    <a  href="/archives">
                        <i class="fa fa-archive"></i>
                        <span>归档</span>
                    </a>
                    
                    <a  href="/friends">
                        <i class="fa fa-envira"></i>
                        <span>友链</span>
                    </a>
                    
                    <a  href="/about">
                        <i class="fa fa-user"></i>
                        <span>关于我</span>
                    </a>
                    
                </nav>
                <a class="mobile-header-menu-button">
                    <i class="fa fa-bars"></i>
                </a>
            </div>
        </div>
        <div id="header-row">
            <div id="logo">
                <a href="/">
                    <img src="/images/avatar/me-130x130.jpg" alt="logo">
                </a>
            </div>
            <div class="header-info">
                <div id="header-title">
                    
                    <h2>
                        清风觅影
                    </h2>
                    
                </div>
                <div id="header-description">
                    
                    <h3>
                        致需极,守静笃
                    </h3>
                    
                </div>
            </div>
            <nav class="header-nav">
                <div class="social">
                    
                        <a title="Home"  href="/">
                            <i class="fa fa-home fa-2x"></i></a>
                    
                        <a title="Github" target="_blank" href="//github.com/bluarry">
                            <i class="fa fa-github fa-2x"></i></a>
                    
                        <a title="mail" target="_blank" href="mailto://bluarry@qq.com">
                            <i class="fa fa-envelope-o fa-2x"></i></a>
                    
                </div>
            </nav>
        </div>
    </div>
</header>
      <div class="outer">
        <section id="main" class="body-wrap"><article id="post-2018-11-07-数据结构复习之kmp算法" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-inner">
    
      <header class="article-header">
        
  
    <h1 class="post-title" itemprop="name">
      数据结构复习之kmp算法
    </h1>
    <div class="post-title-bar">
      <ul>
          
              <li>
                  <i class="fa fa-book"></i>
                  
                      <a href="/categories/默认分类/">默认分类</a>
                  
                      <a href="/categories/经验分享/">经验分享</a>
                  
              </li>
          
        <li>
          <i class="fa fa-calendar"></i>  2018-11-07
        </li>
        <li>
          <i class="fa fa-eye"></i>
          <span id="busuanzi_value_page_pv"></span>
        </li>
      </ul>
    </div>
  

          
      </header>
    
    <div class="article-entry post-content" itemprop="articleBody">
      
            
            <blockquote>
<p>考研时复习专业课时，顺带复习并记录了下来<br><a id="more"></a></p>
<h1>由于考研复习需要，重新复习一遍kmp算法，特此分享</h1>



</blockquote>
<h1>1. 传统的模式匹配算法</h1>

<h2>传统的模式匹配的过程如下:</h2>

<blockquote>
  <ul>
  <li><ol>
  <li>初始时，i,j如图所示，处于S[0]及P[0]，接下来迭代比较S[i]与S[j]，相等就继续比较下一个元素: 
  <img src="https://cdn.bluarry.top/wp-content/uploads/2019/12/a.png" alt="初始化"></li>
  </ol></li>
  <li><ol start="2">
  <li>当S[i]!=S[j]的时候，即失去匹配时，如图:
  <img src="https://cdn.bluarry.top/wp-content/uploads/2019/12/b.png" alt="失去匹配"></li>
  </ol></li>
  <li><ol start="3">
  <li>此时按照传统的做法应该回溯到如图所示的位置:
  <img src="https://cdn.bluarry.top/wp-content/uploads/2019/12/c.png" alt="回溯"></li>
  </ol></li>
  </ul>
</blockquote>

<h2>我相信这个算法的实现方式没有人不会，所以我直接给出伪码:</h2>

<pre><code class="language-cpp line-numbers">int index(string s,stirng p){
    int i=0,j=0;
    while(i&lt;s.length()&amp;&amp;j&lt;p.length()){
        if(s[i]==p[j]){i++;j++;}
        else{
            i=i-j+1;
            j=0;
        }
    }
    if(j&gt;=p.length()) return i-P.length()+1;
    return -1;
}
</code></pre>

<h2>## 仔细分析上边算法的时间复杂度可得，最坏情况下为O(n*m)</h2>

<h1>2. KMP 模式匹配算法</h1>

<h2>(1). 前边算法存在的问题</h2>

<blockquote>
  <h2>依然沿用前边的例子，当失去匹配的时候，状态如下图所示：</h2>

  <img src="https://cdn.bluarry.top/wp-content/uploads/2019/12/b.png" alt="失去匹配">

  <h2>那么此时换做你来选择下一次比较的位置，我相信你肯定不会选择和前边的算法的做法一样，我相信正常的人都会选择如下图所示:</h2>

  <img src="https://cdn.bluarry.top/wp-content/uploads/2019/12/d.png" alt="改进">
</blockquote>

<h2>(2). 为了说明KMP算法的原理，我们换个例子来说明KMP的一次匹配过程。（注： 只讨论匹配过程，不看程序）</h2>

<blockquote>
  <img src="https://cdn.bluarry.top/wp-content/uploads/2019/12/2_a.png" alt="kmp说明例">
  <img src="https://cdn.bluarry.top/wp-content/uploads/2019/12/2_b.png" alt="kmp说明例">
  <img src="https://cdn.bluarry.top/wp-content/uploads/2019/12/2_c.png" alt="kmp说明例">
  <img src="https://cdn.bluarry.top/wp-content/uploads/2019/12/2_d.png" alt="kmp说明例">

  <h2>第2步时，在i,j处失配，此时根据已经比较过的前缀和后缀，如图所示的黄色标记，前边为前缀，后边为后缀</h2>

  <img src="https://cdn.bluarry.top/wp-content/uploads/2019/12/3.png" alt="前后缀说明">

  <h2>根据已经比较过的经验，下一次应该直接用模式串的k+1处的字符跟主串来比较。</h2>
</blockquote>

<h2>(3). 再举几个例子来更充分的说明模式串的挪动过程</h2>

<blockquote>
  ![模式串说明](kmp说明例](/wp-content/uploads/2019/12/4_a.png)
  ![模式串说明](kmp说明例](/wp-content/uploads/2019/12/4_b.png)

  <h2>以上我们已经充分说明了一次kmp匹配过程，以及模式串中前后缀的问题。</h2>

  <h2>其实你所了解kmp算法里的next数组就是让程序来确定这个前后缀的。</h2>

  <h2>先摆出</h2>
</blockquote>

<pre><code class="language-cpp line-numbers">int index(string s,stirng p){
    int i=0,j=0;
    next[]=getnext()   //伪码
    while(i&lt;s.length()&amp;&amp;j&lt;p.length()){
        if(j==-1||s[i]==p[j]){i++;j++;}
        else{
            j=next[j];
        }
    }
    if(j&gt;=p.length()) return i-P.length()+1;
    return -1;
}
</code></pre>

<blockquote>
  <h2>以上给出了kmp算法主程序，那么接下来的问题是如何让程序来知道当前的前后缀，即确定next数组的内容。</h2>
</blockquote>

<h2>3. next数组获取理论</h2>

<blockquote>
  <ul>
  <li>(1).用k表示前缀长度+1</li>
  <li>(2).用j表示当前模式串当前处理的位置</li>
  <li>此时分两种情况
  ** ---------- 1). p[k]==p[j]   即此时可扩展前后缀
  ** ---------- 2). p[k]!=p[j]   即此时不可以扩展前后缀</li>
  </ul>

  <h2>举个例子说明前缀和后缀的获取过程</h2>

  <img src="https://cdn.bluarry.top/wp-content/uploads/2019/12/4_b.png" alt="举例说明">

  <h3>(1). 上例的前缀为: aba  记为pre</h3>

  <h3>(2). 后缀为: aba  结尾end</h3>

  <h3>按照如图所示的情况，此时将p[k]与p[j]分别加入pre和end将导致前后缀不相等，所以，寻找下一个可能的前缀来继续比较加入k处元素是否可以扩展前后缀。</h3>
</blockquote>

<h2>4. 代码实现</h2>

<h3>相信上边的说明已经让你明白了，下面直接写出next数组获取函数</h3>

<pre><code class="language-cpp line-numbers">//伪码
int getnext(string p,next[]){
    int j=0,k=-1;
    next[0]=-1;
    while(j&lt;p.length()){
        if(k==-1||p[j]==p[k]){
            next[++j]=++k;
        }else
            k=next[k]
    }
}
</code></pre>

<h2>上边的kmp还是存在问题，如下图所示</h2>

<blockquote>
  <h2>(图先欠着)</h2>

  <h2>假设在已知一部分前缀和后缀相等，那么此时假如p[k]==p[j],在p[j]处失去匹配，按照上边的kmp会转去k这个地方比较，显然，这次比较是多余的，可省去</h2>

  <h2>做出改进后的实现代码</h2>
</blockquote>

<pre><code class="language-cpp line-numbers">//伪码
int getnext(string p,next[]){
    int j=0,k=-1;
    next[0]=-1;
    while(j&lt;p.length()){
        if(k==-1||p[j]==p[k]){
            ++j;++k;
            if(p[j]==p[k]){
                next[j]=next[k];
            }
            else    
                next[j]=k;
        }else
            k=next[k]
    }
}
</code></pre>

<h2>ps: 由于考研时间紧张，写得粗略，待以后完善</h2>
            <div class="post-copyright">
    <div class="content">
        <p>最后更新： 2020年03月02日 20:53</p>
        <p>原始链接： <a class="post-url" href="/2018/11/07/2018-11-07-数据结构复习之kmp算法/" title="数据结构复习之kmp算法">/2018/11/07/2018-11-07-数据结构复习之kmp算法/</a></p>
        <footer>
            <a href="">
                <img src="/images/avatar/me-130x130.jpg" alt="bluarry">
                bluarry
            </a>
        </footer>
    </div>
</div>

      
        
            
<div class="page-reward">
    <a id="rewardBtn" href="javascript:;">赏</a>
</div>

<div id="reward" class="post-modal reward-lay">
    <a class="close" href="javascript:;" id="reward-close">×</a>
    <span class="reward-title">
        <i class="icon icon-quote-left"></i>
        请我吃糖~
        <i class="icon icon-quote-right"></i>
    </span>
    <div class="reward-content">
        
        <div class="reward-code">
            <img id="rewardCode" src="/images/wechat_code.jpg" alt="打赏二维码">
        </div>
        <div class="reward-select">
            
            <label class="reward-select-item checked" data-id="wechat" data-wechat="/images/wechat_code.jpg">
                <img class="reward-select-item-wechat" src="/images/wechat.png" alt="微信">
            </label>
            
            
            <label class="reward-select-item" data-id="alipay" data-alipay="/images/alipay_code.jpg">
                <img class="reward-select-item-alipay" src="/images/alipay.png" alt="支付宝">
            </label>
            
        </div>
    </div>
</div>


        
    </div>
    <footer class="article-footer">
        
        
<div class="post-share">
    <a href="javascript:;" id="share-sub" class="post-share-fab">
        <i class="fa fa-share-alt"></i>
    </a>
    <div class="post-share-list" id="share-list">
        <ul class="share-icons">
          <li>
            <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=/2018/11/07/2018-11-07-数据结构复习之kmp算法/&title=《数据结构复习之kmp算法》 — 探花需拔根&pic=images/avatar/me-130x130.jpg" data-title="微博">
              <i class="fa fa-weibo"></i>
            </a>
          </li>
          <li>
            <a class="weixin share-sns" id="wxFab" href="javascript:;" data-title="微信">
              <i class="fa fa-weixin"></i>
            </a>
          </li>
          <li>
            <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=/2018/11/07/2018-11-07-数据结构复习之kmp算法/&title=《数据结构复习之kmp算法》 — 探花需拔根&source=
考研时复习专业课时，顺带复习并记录了下来" data-title="QQ">
              <i class="fa fa-qq"></i>
            </a>
          </li>
          <li>
            <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=/2018/11/07/2018-11-07-数据结构复习之kmp算法/" data-title="Facebook">
              <i class="fa fa-facebook"></i>
            </a>
          </li>
          <li>
            <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《数据结构复习之kmp算法》 — 探花需拔根&url=/2018/11/07/2018-11-07-数据结构复习之kmp算法/&via=" data-title="Twitter">
              <i class="fa fa-twitter"></i>
            </a>
          </li>
          <li>
            <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=/2018/11/07/2018-11-07-数据结构复习之kmp算法/" data-title="Google+">
              <i class="fa fa-google-plus"></i>
            </a>
          </li>
        </ul>
     </div>
</div>
<div class="post-modal wx-share" id="wxShare">
    <a class="close" href="javascript:;" id="wxShare-close">×</a>
    <p>扫一扫，分享到微信</p>
    <img src="" alt="微信分享二维码">
</div>

<div class="mask"></div>

        
        <ul class="article-footer-menu">
            
            
  <li class="article-footer-tags">
    <i class="fa fa-tags"></i>
      
    <a href="/tags/算法/" class="color3">算法</a>
      
    <a href="/tags/数据结构/" class="color5">数据结构</a>
      
    <a href="/tags/复习/" class="color3">复习</a>
      
  </li>

        </ul>
        
        

    <aside class="post-toc-pos post-toc-top" id="post-toc">
        <nav class="post-toc-wrap">
            <ol class="post-toc"><li class="post-toc-item post-toc-level-1"><a class="post-toc-link" href="#null"><span class="post-toc-text">由于考研复习需要，重新复习一遍kmp算法，特此分享</span></a></li><li class="post-toc-item post-toc-level-1"><a class="post-toc-link" href="#null"><span class="post-toc-text">1. 传统的模式匹配算法</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#null"><span class="post-toc-text">传统的模式匹配的过程如下:</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#null"><span class="post-toc-text">我相信这个算法的实现方式没有人不会，所以我直接给出伪码:</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#null"><span class="post-toc-text">## 仔细分析上边算法的时间复杂度可得，最坏情况下为O(n*m)</span></a></li></ol></li><li class="post-toc-item post-toc-level-1"><a class="post-toc-link" href="#null"><span class="post-toc-text">2. KMP 模式匹配算法</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#null"><span class="post-toc-text">(1). 前边算法存在的问题</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#null"><span class="post-toc-text">依然沿用前边的例子，当失去匹配的时候，状态如下图所示：</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#null"><span class="post-toc-text">那么此时换做你来选择下一次比较的位置，我相信你肯定不会选择和前边的算法的做法一样，我相信正常的人都会选择如下图所示:</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#null"><span class="post-toc-text">(2). 为了说明KMP算法的原理，我们换个例子来说明KMP的一次匹配过程。（注： 只讨论匹配过程，不看程序）</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#null"><span class="post-toc-text">第2步时，在i,j处失配，此时根据已经比较过的前缀和后缀，如图所示的黄色标记，前边为前缀，后边为后缀</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#null"><span class="post-toc-text">根据已经比较过的经验，下一次应该直接用模式串的k+1处的字符跟主串来比较。</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#null"><span class="post-toc-text">(3). 再举几个例子来更充分的说明模式串的挪动过程</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#null"><span class="post-toc-text">以上我们已经充分说明了一次kmp匹配过程，以及模式串中前后缀的问题。</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#null"><span class="post-toc-text">其实你所了解kmp算法里的next数组就是让程序来确定这个前后缀的。</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#null"><span class="post-toc-text">先摆出</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#null"><span class="post-toc-text">以上给出了kmp算法主程序，那么接下来的问题是如何让程序来知道当前的前后缀，即确定next数组的内容。</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#null"><span class="post-toc-text">3. next数组获取理论</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#null"><span class="post-toc-text">举个例子说明前缀和后缀的获取过程</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#null"><span class="post-toc-text">(1). 上例的前缀为: aba  记为pre</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#null"><span class="post-toc-text">(2). 后缀为: aba  结尾end</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#null"><span class="post-toc-text">按照如图所示的情况，此时将p[k]与p[j]分别加入pre和end将导致前后缀不相等，所以，寻找下一个可能的前缀来继续比较加入k处元素是否可以扩展前后缀。</span></a></li></ol></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#null"><span class="post-toc-text">4. 代码实现</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#null"><span class="post-toc-text">相信上边的说明已经让你明白了，下面直接写出next数组获取函数</span></a></li></ol></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#null"><span class="post-toc-text">上边的kmp还是存在问题，如下图所示</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#null"><span class="post-toc-text">(图先欠着)</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#null"><span class="post-toc-text">假设在已知一部分前缀和后缀相等，那么此时假如p[k]==p[j],在p[j]处失去匹配，按照上边的kmp会转去k这个地方比较，显然，这次比较是多余的，可省去</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#null"><span class="post-toc-text">做出改进后的实现代码</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#null"><span class="post-toc-text">ps: 由于考研时间紧张，写得粗略，待以后完善</span></a></li></ol></li></ol>
        </nav>
    </aside>
    

<nav id="article-nav">
  
    <a href="/2019/01/01/2019-01-01-tmux使用常见的快捷键/" id="article-nav-newer" class="article-nav-link-wrap">

      <span class="article-nav-title">
        <i class="fa fa-hand-o-left" aria-hidden="true"></i>
        
          tmux使用常见的快捷键
        
      </span>
    </a>
  
  
    <a href="/2018/09/24/2018-09-24-算法之算法复杂度分析/" id="article-nav-older" class="article-nav-link-wrap">
      <span class="article-nav-title">算法之算法复杂度分析</span>
      <i class="fa fa-hand-o-right" aria-hidden="true"></i>
    </a>
  
</nav>




    <!-- HTML页面布局 -->
    <div id="tab-list">
        <ul id="ul1">
            
            
            
            <li id="gittalk" style="width: 25%;">gittalk</li>
            
            
            <li id="valine" style="width: 25%;">valine</li>
            
        </ul>
         
        
          
        <div id="dv_gitment" class="hide">
            <div id="git_comments"></div>;
        </div>
        
        
        <div id="dv_vment" class="show">
            <div class="comments vcomment" id="vcomments"></div>
        </div>
        
    </div>

    <script src="/js/tablist.js"></script>
   

    
        
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.css">
<script src="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js"></script>
<script src="https://cdn.bluarry.top/cdn/js/md5.min.js"></script>
<!--<div id="git_comments"></div>-->
<script>
    // var gitment = new Gitment({
    //     owner: 'bluarry',
    //     repo: 'blog_comment',
    //     oauth: {
    //         client_id: '5c95f5b820d109c8f5c1',
    //         client_secret: 'f1cfe5b08f9a55923ba26a9ec8855b631002ad18',
    //     },
    // })
    var hrefs=location.href;
    var links=hrefs.split('/');
    var cr="";
    for (var i=0;i<Math.min(7,links.length);i++) {
        cr+=links[i];
    }
    console.log(cr);

    var gitalk = new Gitalk({
        clientID: '5c95f5b820d109c8f5c1', //Client ID
        clientSecret: 'f1cfe5b08f9a55923ba26a9ec8855b631002ad18', //Client Secret
        repo: 'blog_comment',//仓库名称
        owner: 'bluarry',//仓库拥有者
        admin: ['bluarry'],
        id: md5(cr),      // Ensure uniqueness and length less than 50
        distractionFreeMode: false  // Facebook-like distraction free mode
    });
    gitalk.render('git_comments');
</script>


    
        <!-- Valine Comments -->
<!-- <div class="comments vcomment" id="vcomments"></div>-->
<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src="//unpkg.com/valine@latest/dist/Valine.min.js"></script>
<!-- Valine Comments script -->
<script>
    var GUEST_INFO = ['nick','mail','link'];
    var guest_info = 'nick,mail'.split(',').filter(function(item){
        return GUEST_INFO.indexOf(item) > -1
    });
    new Valine({
        el: '#vcomments',
        notify: 'true' == 'true',
        verify: 'false' == 'true',
        appId: "DRrkhLYTmB6QwGy6sI6vCH8C-gzGzoHsz",
        appKey: "M4A4lrKwbixQmmeO5lVdY5l2",
        avatar: "mm",
        placeholder: "少侠，留下你的评论吧",
        guest_info: guest_info.length == 0 ? GUEST_INFO : guest_info,
        pageSize: "10"
    })
</script>
<!-- Valine Comments end -->

    


    </footer>
  </div>
</article>


</section>
        
      </div>
      <footer id="footer">
  <div class="outer">
    <div id="footer-info" class="inner">
      
<p>
    <span id="busuanzi_container_site_uv" style='display:none'>
        <i class="fa fa-user"></i>&nbsp;&nbsp;<span id="busuanzi_value_site_uv"></span>
    </span>&nbsp;&nbsp;|&nbsp;&nbsp;
    <span id="busuanzi_container_site_pv" style='display:none'>
        <i class="fa fa-eye"></i> &nbsp;&nbsp;<span id="busuanzi_value_site_pv"></span>
    </span>
</p>


      <p>
      &copy; 2016-2021 &nbsp;&nbsp;<i style="color: red;" class="fa fa-heart"></i>&nbsp;&nbsp; bluarry
      备案号: <a style="color: #999;" href="http://www.beian.miit.gov.cn/" target="_blank">陕ICP备2020012959号</a>
    </p>

    </div>
  </div>
</footer>
    <script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<script src="//cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<script>
  var mihoConfig = {
      root: "",
      animate: true,
      isHome: false,
      share: true,
      reward: 1
  }
</script>
<div class="sidebar">
    <div id="sidebar-search" title="Search">
        <i class="fa fa-search"></i>
    </div>
    <div id="sidebar-category" title="Categories">
        <i class="fa fa-book"></i>
    </div>
    <div id="sidebar-tag" title="Tags">
        <i class="fa fa-tags"></i>
    </div>
    <div id="sidebar-top">
        <span class="sidebar-top-icon"><i class="fa fa-angle-up"></i></span>
    </div>
</div>
<div class="sidebar-menu-box" id="sidebar-menu-box">
    <div class="sidebar-menu-box-container">
        <div id="sidebar-menu-box-categories">
            <a class="category-link" href="/categories/linux/">linux</a><a class="category-link" href="/categories/linux-学习/">linux 学习</a><a class="category-link" href="/categories/linux-学习-acm-onlinejudge-hustoj/">linux 学习 acm onlinejudge hustoj</a><a class="category-link" href="/categories/学习分享/">学习分享</a><a class="category-link" href="/categories/数据结构/">数据结构</a><a class="category-link" href="/categories/经验分享/">经验分享</a><a class="category-link" href="/categories/经验分享/学习分享/">学习分享</a><a class="category-link" href="/categories/默认分类/">默认分类</a><a class="category-link" href="/categories/默认分类/复习/">复习</a><a class="category-link" href="/categories/默认分类/复习/学习分享/">学习分享</a><a class="category-link" href="/categories/默认分类/学习分享/">学习分享</a><a class="category-link" href="/categories/默认分类/生活杂谈/">生活杂谈</a><a class="category-link" href="/categories/默认分类/经验分享/">经验分享</a><a class="category-link" href="/categories/默认分类/经验分享/学习分享/">学习分享</a>
        </div>
        <div id="sidebar-menu-box-tags">
            <a href="/tags/Java/" style="font-size: 10px;">Java</a> <a href="/tags/acm/" style="font-size: 12.86px;">acm</a> <a href="/tags/android/" style="font-size: 11.43px;">android</a> <a href="/tags/c/" style="font-size: 14.29px;">c++</a> <a href="/tags/fabric/" style="font-size: 11.43px;">fabric</a> <a href="/tags/kali/" style="font-size: 10px;">kali</a> <a href="/tags/linux/" style="font-size: 15.71px;">linux</a> <a href="/tags/linux学习/" style="font-size: 10px;">linux学习</a> <a href="/tags/mac/" style="font-size: 10px;">mac</a> <a href="/tags/mfc/" style="font-size: 10px;">mfc</a> <a href="/tags/onlinejudge/" style="font-size: 10px;">onlinejudge</a> <a href="/tags/sqlite/" style="font-size: 10px;">sqlite</a> <a href="/tags/sqlite3/" style="font-size: 11.43px;">sqlite3</a> <a href="/tags/ss/" style="font-size: 10px;">ss</a> <a href="/tags/vs/" style="font-size: 11.43px;">vs</a> <a href="/tags/xposed/" style="font-size: 10px;">xposed</a> <a href="/tags/xposed模块/" style="font-size: 10px;">xposed模块</a> <a href="/tags/专业知识/" style="font-size: 10px;">专业知识</a> <a href="/tags/侧链/" style="font-size: 10px;">侧链</a> <a href="/tags/内网穿透/" style="font-size: 10px;">内网穿透</a> <a href="/tags/区块链/" style="font-size: 11.43px;">区块链</a> <a href="/tags/复习/" style="font-size: 10px;">复习</a> <a href="/tags/学习/" style="font-size: 18.57px;">学习</a> <a href="/tags/安卓/" style="font-size: 12.86px;">安卓</a> <a href="/tags/小技巧/" style="font-size: 17.14px;">小技巧</a> <a href="/tags/数据库/" style="font-size: 10px;">数据库</a> <a href="/tags/数据结构/" style="font-size: 10px;">数据结构</a> <a href="/tags/日常使用问题/" style="font-size: 10px;">日常使用问题</a> <a href="/tags/最小生成树/" style="font-size: 11.43px;">最小生成树</a> <a href="/tags/最短路径/" style="font-size: 10px;">最短路径</a> <a href="/tags/比特币/" style="font-size: 11.43px;">比特币</a> <a href="/tags/算法/" style="font-size: 12.86px;">算法</a> <a href="/tags/算法笔记/" style="font-size: 11.43px;">算法笔记</a> <a href="/tags/经验/" style="font-size: 20px;">经验</a> <a href="/tags/编译原理/" style="font-size: 10px;">编译原理</a> <a href="/tags/翻译/" style="font-size: 10px;">翻译</a> <a href="/tags/自然计算/" style="font-size: 10px;">自然计算</a>
        </div>
    </div>
    <a href="javascript:;" class="sidebar-menu-box-close">&times;</a>
</div>
<div class="mobile-header-menu-nav" id="mobile-header-menu-nav">
    <div class="mobile-header-menu-container">
        <span class="title">Menus</span>
        <ul class="mobile-header-menu-navbar">
            
            <li>
                <a  href="/">
                    <i class="fa fa-home"></i><span>主页</span>
                </a>
            </li>
            
            <li>
                <a  href="/archives">
                    <i class="fa fa-archive"></i><span>归档</span>
                </a>
            </li>
            
            <li>
                <a  href="/friends">
                    <i class="fa fa-envira"></i><span>友链</span>
                </a>
            </li>
            
            <li>
                <a  href="/about">
                    <i class="fa fa-user"></i><span>关于我</span>
                </a>
            </li>
            
        </ul>
    </div>
    <div class="mobile-header-tag-container">
        <span class="title">Tags</span>
        <div id="mobile-header-container-tags">
            <a href="/tags/Java/" style="font-size: 10px;">Java</a> <a href="/tags/acm/" style="font-size: 12.86px;">acm</a> <a href="/tags/android/" style="font-size: 11.43px;">android</a> <a href="/tags/c/" style="font-size: 14.29px;">c++</a> <a href="/tags/fabric/" style="font-size: 11.43px;">fabric</a> <a href="/tags/kali/" style="font-size: 10px;">kali</a> <a href="/tags/linux/" style="font-size: 15.71px;">linux</a> <a href="/tags/linux学习/" style="font-size: 10px;">linux学习</a> <a href="/tags/mac/" style="font-size: 10px;">mac</a> <a href="/tags/mfc/" style="font-size: 10px;">mfc</a> <a href="/tags/onlinejudge/" style="font-size: 10px;">onlinejudge</a> <a href="/tags/sqlite/" style="font-size: 10px;">sqlite</a> <a href="/tags/sqlite3/" style="font-size: 11.43px;">sqlite3</a> <a href="/tags/ss/" style="font-size: 10px;">ss</a> <a href="/tags/vs/" style="font-size: 11.43px;">vs</a> <a href="/tags/xposed/" style="font-size: 10px;">xposed</a> <a href="/tags/xposed模块/" style="font-size: 10px;">xposed模块</a> <a href="/tags/专业知识/" style="font-size: 10px;">专业知识</a> <a href="/tags/侧链/" style="font-size: 10px;">侧链</a> <a href="/tags/内网穿透/" style="font-size: 10px;">内网穿透</a> <a href="/tags/区块链/" style="font-size: 11.43px;">区块链</a> <a href="/tags/复习/" style="font-size: 10px;">复习</a> <a href="/tags/学习/" style="font-size: 18.57px;">学习</a> <a href="/tags/安卓/" style="font-size: 12.86px;">安卓</a> <a href="/tags/小技巧/" style="font-size: 17.14px;">小技巧</a> <a href="/tags/数据库/" style="font-size: 10px;">数据库</a> <a href="/tags/数据结构/" style="font-size: 10px;">数据结构</a> <a href="/tags/日常使用问题/" style="font-size: 10px;">日常使用问题</a> <a href="/tags/最小生成树/" style="font-size: 11.43px;">最小生成树</a> <a href="/tags/最短路径/" style="font-size: 10px;">最短路径</a> <a href="/tags/比特币/" style="font-size: 11.43px;">比特币</a> <a href="/tags/算法/" style="font-size: 12.86px;">算法</a> <a href="/tags/算法笔记/" style="font-size: 11.43px;">算法笔记</a> <a href="/tags/经验/" style="font-size: 20px;">经验</a> <a href="/tags/编译原理/" style="font-size: 10px;">编译原理</a> <a href="/tags/翻译/" style="font-size: 10px;">翻译</a> <a href="/tags/自然计算/" style="font-size: 10px;">自然计算</a>
        </div>
    </div>
</div>
<div class="search-wrap">
    <span class="search-close">&times;</span>
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="back">
            <i class="icon icon-lg icon-chevron-left"></i>
        </a>
        <input class="search-field" placeholder="Search..." id="keywords">
        <a id="search-submit" href="javascript:;">
            <i class="fa fa-search"></i>
        </a>
    <div class="search-container" id="search-container">
        <ul class="search-result" id="search-result">
        </ul>
    </div>
</div>

<div id="search-tpl">
    <li class="search-result-item">
        <a href="{url}" class="search-item-li">
            <span class="search-item-li-title" title="{title}">{title}</span>
        </a>
    </li>
</div>
<script src="/js/search.js"></script>
<script src="/js/main.js"></script>


  <script src="//cdn.bootcss.com/particles.js/2.0.0/particles.min.js"></script>
  <div id="particles"></div>
  <script src="/js/particles.js"></script>







  <link rel="stylesheet" href="//cdn.bootcss.com/animate.css/3.5.0/animate.min.css">
  <script src="//cdn.bootcss.com/scrollReveal.js/3.0.5/scrollreveal.js"></script>
  <script src="/js/animate.js"></script>


  <script src="/js/pop-img.js"></script>
  <script>
     $(".article-entry p img").popImg();
  </script>

  </div>
</body>
</html>